﻿Imports System.Linq

Namespace Aricie.DNN.Services.Url.FriendlyUrl.Controls.UICommands

    Friend Class FUPCommandFactory
        Private Shared CommandFactories As New Dictionary(Of String, Func(Of String, IFUPCOmmand))
        Shared Sub New()
            CommandFactories.Add("LIST", Function(parameters) New ReorderGroupsCommand() With {.CommandArgs = parameters})
            CommandFactories.Add("EDIT", Function(parameters) New EditGroupCommand() With {.CommandArgs = parameters})
            CommandFactories.Add("DELETE", Function(parameters) New DeleteGroupCommand() With {.CommandArgs = parameters})
        End Sub

        Public Shared Function RetrieveCommand(CommandText As String) As IFUPCOmmand
            Dim CommandName As New String(CommandText.TakeWhile(Function(c) c <> ":"c).ToArray())
            Dim CommandParameter As New String(CommandText.SkipWhile(Function(c) c <> ":"c).Skip(1).ToArray())

            Return CommandFactories(CommandName)(CommandParameter)
        End Function

    End Class
End Namespace